﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.XmlConfig;

namespace ZWZ.Web.WebAdmin
{
    public partial class m : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Image1.AlternateText = Codes.LoginHelper.CurrentUser.NickName;
                //Image1.ImageUrl = Codes.LoginHelper.CurrentUser.PicUrl;
                //string 已发送未读 = ZWZ.Enums.User.MessageStatus.已发送未读.ToString();
                //string 未发送草稿 = ZWZ.Enums.User.MessageStatus.未发送草稿.ToString();
                //string 公告 = ZWZ.Enums.User.MessageType.公告.ToString();
                //string 私信 = ZWZ.Enums.User.MessageType.私信.ToString();
                //string 提问 = ZWZ.Enums.User.MessageType.提问.ToString();
                //string CurrentUserID = Codes.LoginHelper.CurrentUser.ID;
                //var MsgGroups = DBProvider.DB.Ctx.User_Message
                //    .Where(i => i.ReciverID == CurrentUserID)
                //    .GroupBy(i => new { i.Type, i.Status })
                //    .Select(arg => new
                //{
                //    MsgType = arg.Key.Type,
                //    MsgStatus = arg.Key.Status,
                //    Count = arg.Count()
                //}).ToList();

                //var 未读私信 = MsgGroups.Where(i => i.MsgType == 私信 && i.MsgStatus == 已发送未读).Sum(i => i.Count);
                //var 所有私信 = MsgGroups.Where(i => i.MsgType == 私信 && i.MsgStatus != 未发送草稿).Sum(i => i.Count);
                //lab_msg.Text = 未读私信 + "/" + 所有私信;

                //var 未读公告 = MsgGroups.Where(i => i.MsgType == 公告 && i.MsgStatus == 已发送未读).Sum(i => i.Count);
                //var 所有公告 = MsgGroups.Where(i => i.MsgType == 公告 && i.MsgStatus != 未发送草稿).Sum(i => i.Count);
                //lab_note.Text = 未读公告 + "/" + 所有公告;

                //var 未读提问 = MsgGroups.Where(i => i.MsgType == 提问 && i.MsgStatus == 已发送未读).Sum(i => i.Count);
                //var 所有提问 = MsgGroups.Where(i => i.MsgType == 提问 && i.MsgStatus != 未发送草稿).Sum(i => i.Count);
                //lab_ask.Text = 未读提问 + "/" + 所有提问;

                lab_NickName.Text = Codes.LoginHelper.CurrentUser.NickName;
                Rpt_MenuGroup.DataSource = Config.ConfigAdapter.AdminMenu.Groups.Skip(1);
                Rpt_MenuGroup.DataBind();
            }
        }
        protected void Rpt_MenuGroup_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            ConfigGroup group = e.Item.DataItem as ConfigGroup;
            Repeater Rpt_MenuSettings = e.Item.FindControl("Rpt_MenuSettings") as Repeater;
            Rpt_MenuSettings.DataSource = group.Settings;
            Rpt_MenuSettings.DataBind();
        }
        protected void Rpt_MenuSetting_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            ConfigSetting setting = e.Item.DataItem as ConfigSetting;
            Label Lab_Img = e.Item.FindControl("lab_Img") as Label;
            if (setting.Attrs["Style"] != null) { Lab_Img.Attributes["Style"] = setting.Attrs["Style"].Value; }

            HyperLink lnk_Text = e.Item.FindControl("lnk_Text") as HyperLink;
            lnk_Text.Text = setting.Text;
            lnk_Text.NavigateUrl = setting.Value;
            if (setting.Attrs["Target"] != null) lnk_Text.Target = setting.Attrs["Target"].Value;
        }
    }
}